<template>
  <div>
    <!-- 营收列表 -->
    <div>
      <div style="display: flex;justify-content: center;">
        <div style="font-size: 20px;font-weight:700;color:#3a71a8;text-align: center;margin-bottom:10px">
          {{ luser.companyName }}车辆营收统计表</div>
        <el-button size="small" @click="ex_getWalletListForBack_btn" style="margin-left: 20px;"
          type="warning">导出</el-button>
      </div>
      <div class="time-wrapper">

        <div>
          <el-select size="small" multiple collapse-tags clearable v-model="find_data.plateNums" :placeholder="'车牌号'"
            style="width: 140px;margin-left:10px;">
            <el-option v-for="item in carNumList" :key="item.id" :label="item.plate_num" :value="item.plate_num">
            </el-option>
          </el-select>

          <el-select size="small" style="margin-left: 5px;width:120px" v-model="find_data.driverUserId"
            placeholder="驾驶员" clearable>
            <el-option v-for="item in getDriverCombo_list" :key="item.id" :label="item.realName"
              :value="item.ftUserId" />
          </el-select>

          <el-date-picker size="small" :default-time="defaultTime" style="margin-left: 5px;width: 200px;"
            v-model="timeTypeTime" @change="timeTypeTime_btn" type="daterange" range-separator="至"
            start-placeholder="开始时间" end-placeholder="结束时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />




        </div>

      </div>
      <div class="time-wrapper2">
        <el-select @change="list_api()" size="small" v-model="find_data.carBelongType" :placeholder="'车辆营收统计'"
          style="width: 140px;margin-left:10px;">
          <el-option label="自营车" value="0">
          </el-option>
          <el-option label="外调车" value="1">
          </el-option>
        </el-select>
        <el-button style="margin-left: 5px;" size="small" type="primary" @click="list_api()">搜索</el-button>
      </div>
      <div class="empty-car-list">
        <div>
          <div v-if="carBelongType_off == '0'" class="car-list">
            <table border="2" align="center">
              <tbody>
                <!-- <tr>
                  <th colspan="6"> {{ luser.companyName }}车辆营收统计表</th>
                </tr> -->


                <tr>
                  <td class="td1">车牌号</td>
                  <td colspan="5">{{ plateNumsname }}</td>
                </tr>


                <tr>
                  <td class="td1">时间周期</td>
                  <td colspan="2">{{ timeTypeTime[0] }}</td>
                  <td>至</td>
                  <td colspan="2">{{ timeTypeTime[1] }}</td>


                </tr>


                <tr>
                  <td class="td1" rowspan="5">自营收入</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2">已收款</td>
                  <td class="td2">未收款</td>
                  <td class="td2">未收款比</td>
                </tr>


                <tr>

                  <td>总收入</td>
                  <td class="td3">{{ list_data.totalPrice }}</td>
                  <td>{{ list_data.totalAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalGathSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalNoGathRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>行程收入</td>
                  <td class="td3">{{ list_data.totalBcPrice }}</td>
                  <td>{{ list_data.totalBcAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalBcGathSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalBcNoGathRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>接送收入</td>
                  <td class="td3">{{ list_data.totalJsPrice }}</td>
                  <td>{{ list_data.totalJsAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalJsGathSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalJsNoGathRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>其他收入</td>
                  <td class="td3">{{ list_data.totalOtherGath }}</td>
                  <td>{{ list_data.totalOtherAlGath }}</td>
                  <td class="td4">{{ list_data.totalOtherNoGath }}</td>
                  <td>{{ Math.round(list_data.totalOtherAlGathRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td class="td1" rowspan="11">行程开支</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2">已支付</td>
                  <td class="td2">未支付</td>
                  <td class="td2">开支比</td>
                </tr>


                <tr>
                  <td>总开支</td>
                  <td class="td3">{{ list_data.totalPay }}</td>
                  <td>{{ list_data.totalAlPay }}</td>
                  <td class="td4">{{ list_data.totalNoPay }}</td>
                  <td>{{ Math.round(list_data.totalPayRatio * 100) }}%</td>

                </tr>





                <tr>
                  <td>停车费</td>
                  <td class="td3">{{ list_data.parkingFee }}</td>
                  <td>{{ list_data.parkingFeeAlPay }}</td>
                  <td class="td4">{{ list_data.parkingFeeNoPay }}</td>

                  <td>{{ Math.round(list_data.parkingFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>过路费</td>
                  <td class="td3">{{ list_data.roadFee }}</td>
                  <td>{{ list_data.roadFeeAlPay }}</td>
                  <td class="td4">{{ list_data.roadFeeNoPay }}</td>

                  <td>{{ Math.round(list_data.roadFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>餐费</td>
                  <td class="td3">{{ list_data.livingFee }}</td>
                  <td>{{ list_data.livingFeeAlPay }}</td>
                  <td class="td4">{{ list_data.livingFeeNoPay }}</td>

                  <td>{{ Math.round(list_data.livingFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>住宿费</td>
                  <td class="td3">{{ list_data.stayFee }}</td>
                  <td>{{ list_data.stayFeeAlPay }}</td>
                  <td class="td4">{{ list_data.stayFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.stayFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>买水费</td>
                  <td class="td3">{{ list_data.waterFee }}</td>
                  <td>{{ list_data.waterFeeAlPay }}</td>
                  <td class="td4">{{ list_data.waterFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.waterFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>洗车费</td>
                  <td class="td3">{{ list_data.washingFee }}</td>
                  <td>{{ list_data.washingFeeAlPay }}</td>
                  <td class="td4">{{ list_data.washingFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.washingFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>打的费</td>
                  <td class="td3">{{ list_data.taxiFee }}</td>
                  <td>{{ list_data.taxiFeeAlPay }}</td>
                  <td class="td4">{{ list_data.taxiFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.taxiFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>打单费</td>
                  <td class="td3">{{ list_data.singleFee }}</td>
                  <td>{{ list_data.singleFeeAlPay }}</td>
                  <td class="td4">{{ list_data.singleFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.singleFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>其他费</td>
                  <td class="td3">{{ list_data.otherFee }}</td>
                  <td>{{ list_data.otherFeeAlPay }}</td>
                  <td class="td4">{{ list_data.otherFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.otherFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td class="td1" rowspan="10">其他开支</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2">已支付</td>
                  <td class="td2">未支付</td>
                  <td class="td2">开支比</td>
                </tr>


                <tr>
                  <td>总开支</td>
                  <td class="td3">{{ list_data.totalOfficePay }}</td>
                  <td>{{ list_data.totalOfficeAlPay }}</td>
                  <td class="td4">{{ list_data.totalOfficeNoPay }}</td>
                  <td>{{ Math.round(list_data.totalOfficePayRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>司机工资</td>
                  <td class="td3">{{ list_data.salaryFee }}</td>
                  <td>{{ list_data.salaryFeeAlPay }}</td>
                  <td class="td4">{{ list_data.salaryFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.salaryFeeRatio * 100) }}%</td>
                </tr>
                <tr>
                  <td>油费</td>
                  <td class="td3">{{ list_data.oilFee }}</td>
                  <td>{{ list_data.oilFeeAlPay }}</td>
                  <td class="td4">{{ list_data.oilFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.oilFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>维修费</td>
                  <td class="td3">{{ list_data.repairFee }}</td>
                  <td>{{ list_data.repairFeeAlPay }}</td>
                  <td class="td4">{{ list_data.repairFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.repairFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>保养费</td>
                  <td class="td3">{{ list_data.maintenanceFee }}</td>
                  <td>{{ list_data.maintenanceFeeAlPay }}</td>
                  <td class="td4">{{ list_data.maintenanceFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.maintenanceFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>业务赔款</td>
                  <td class="td3">{{ list_data.compensateFee }}</td>
                  <td>{{ list_data.compensateFeeAlPay }}</td>
                  <td class="td4">{{ list_data.compensateFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.compensateFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>规费</td>
                  <td class="td3">{{ list_data.guiFee }}</td>
                  <td>{{ list_data.guiFeeAlPay }}</td>
                  <td class="td4">{{ list_data.guiFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.guiFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>车辆保险</td>
                  <td class="td3">{{ list_data.insuranceFee }}</td>
                  <td>{{ list_data.insuranceFeeAlPay }}</td>
                  <td class="td4">{{ list_data.insuranceFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.insuranceFeeRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>其他开支</td>
                  <td class="td3">{{ list_data.otherMoreFee }}</td>
                  <td>{{ list_data.otherMoreFeeAlPay }}</td>
                  <td class="td4">{{ list_data.otherMoreFeeNoPay }}</td>
                  <td>{{ Math.round(list_data.otherMoreFeeRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td class="td1" rowspan="2">利润</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2"></td>
                  <td class="td2"></td>
                  <td class="td2">利润比</td>
                </tr>


                <tr>
                  <td>毛利润</td>
                  <td class="td3">{{ list_data.grossProfit }}</td>
                  <td></td>
                  <td class="td4"></td>
                  <td>{{ Math.round(list_data.grossProfitRatio * 100) }}%</td>

                </tr>

              </tbody>
            </table>

          </div>
          <div v-if="carBelongType_off == '1'" class="car-list">
            <table border="2" align="center">
              <tbody>
                <!-- <tr>
                  <th colspan="6"> {{ luser.companyName }}车辆营收统计表</th>
                </tr> -->


                <tr>
                  <td class="td1">车牌号</td>
                  <td colspan="5">{{ plateNumsname }}</td>
                </tr>


                <tr>
                  <td class="td1">时间周期</td>
                  <td colspan="2">{{ timeTypeTime[0] }}</td>
                  <td>至</td>
                  <td colspan="2">{{ timeTypeTime[1] }}</td>


                </tr>


                <tr>
                  <td class="td1" rowspan="4">外调收入</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2">已收款</td>
                  <td class="td2">未收款</td>
                  <td class="td2">未收款比</td>
                </tr>


                <tr>

                  <td>总收入</td>
                  <td class="td3">{{ list_data.totalPrice }}</td>
                  <td>{{ list_data.totalAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalGathSubPrice }}</td>

                  <td>{{ Math.round(list_data.totalNoGathRatio * 100) }}%</td>
                </tr>


                <tr>
                  <td>行程收入</td>
                  <td class="td3">{{ list_data.totalBcPrice }}</td>
                  <td>{{ list_data.totalBcAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalBcGathSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalBcNoGathRatio * 100) }}%</td>

                </tr>


                <tr>
                  <td>接送收入</td>
                  <td class="td3">{{ list_data.totalJsPrice }}</td>
                  <td>{{ list_data.totalJsAlGathPrice }}</td>
                  <td class="td4">{{ list_data.totalJsGathSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalJsNoGathRatio * 100) }}%</td>
                </tr>








                <tr>
                  <td class="td1" rowspan="2">外调开支</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2">已支付</td>
                  <td class="td2">未支付</td>
                  <td class="td2">开支比</td>
                </tr>


                <tr>
                  <td>总开支</td>
                  <td class="td3">{{ list_data.totalOutPrice }}</td>
                  <td>{{ list_data.totalOutAIPrice }}</td>
                  <td class="td4">{{ list_data.totalOutSubPrice }}</td>
                  <td>{{ Math.round(list_data.totalOutNoPayRatio * 100) }}%</td>

                </tr>





                <tr>
                  <td class="td1" rowspan="2">利润</td>
                  <td class="td2">项目</td>
                  <td class="td2">总金额</td>
                  <td class="td2"></td>
                  <td class="td2"></td>
                  <td class="td2">利润比</td>
                </tr>


                <tr>
                  <td>毛利润</td>
                  <td class="td3">{{ list_data.grossProfit }}</td>
                  <td></td>
                  <td class="td4"></td>
                  <td>{{ Math.round(list_data.grossProfitRatio * 100) }}%</td>

                </tr>

              </tbody>
            </table>

          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import {
  findCarCombo, getDriverList, revenueSum

} from '@/api/login.js'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import * as XLSX from 'xlsx';
onMounted(() => {
  luser.value = JSON.parse(localStorage.getItem("luser"))
  timeTypeTime.value = [new_day1(), to_day1()]
  find_data.stime = new_day()
  find_data.etime = to_day()
  findCarCombo({
    page: {
      pageNum: 1,
      pageSize: 999,
    },
    plateNum: '',
    companyNums: luser.companyNum,
  }).then(res => {

    carNumList.value = res.data.list || [];
  })
  getDriverList({
    containLeave: '0',
    containMain: "0",
  }).then(res => {
    getDriverCombo_list.value = res.data
  })
  list_api()
})
const luser = ref({})
const carNumList = ref([])
const getDriverCombo_list = ref([])
const defaultTime = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
const timeTypeTime = ref([])
const timeTypeTime_btn = (e) => {
  if (e) {
    timeTypeTime.value = e
    find_data.stime = timeTypeTime.value[0] + ' ' + '00:00:00'
    find_data.etime = timeTypeTime.value[1] + ' ' + '23:59:59'
    find_data.timeType = '0'
  } else {
    timeTypeTime.value = ''
    find_data.stime = ''
    find_data.etime = ''
    find_data.timeType = ''
  }
}

const new_day = () => {
  // 获取当前日期
  let currentDate = new Date();

  // 计算上个月的年份和月份
  let year = currentDate.getMonth() === 0 ? currentDate.getFullYear() - 1 : currentDate.getFullYear();
  let month = currentDate.getMonth() === 0 ? 11 : currentDate.getMonth() - 1;

  // 构建上个月的日期
  let firstDayOfLastMonth = new Date(year, month, 1);

  // 格式化为 yyyy-mm-dd
  let formattedDate = `${firstDayOfLastMonth.getFullYear()}-${(firstDayOfLastMonth.getMonth() + 1).toString().padStart(2, '0')}-01`;

  let formattedDate2 = `${formattedDate} 00:00:00`;
  return formattedDate2
}
const to_day = () => {
  // 获取当前日期
  let currentDate = new Date();

  // 计算上个月的年份和月份
  let year = currentDate.getMonth() === 0 ? currentDate.getFullYear() - 1 : currentDate.getFullYear();
  let month = currentDate.getMonth() === 0 ? 11 : currentDate.getMonth() - 1;

  // 获取上个月的最后一天
  let lastDayOfLastMonth = new Date(year, month + 1, 0);

  // 格式化为 yyyy-mm-dd
  let formattedDate = `${lastDayOfLastMonth.getFullYear()}-${(lastDayOfLastMonth.getMonth() + 1).toString().padStart(2, '0')}-${lastDayOfLastMonth.getDate()}`;

  let formattedDate2 = `${formattedDate} 23:59:59`;
  return formattedDate2
}
const new_day1 = () => {
  // 获取当前日期
  let currentDate = new Date();

  // 计算上个月的年份和月份
  let year = currentDate.getMonth() === 0 ? currentDate.getFullYear() - 1 : currentDate.getFullYear();
  let month = currentDate.getMonth() === 0 ? 11 : currentDate.getMonth() - 1;

  // 构建上个月的日期
  let firstDayOfLastMonth = new Date(year, month, 1);

  // 格式化为 yyyy-mm-dd
  let formattedDate = `${firstDayOfLastMonth.getFullYear()}-${(firstDayOfLastMonth.getMonth() + 1).toString().padStart(2, '0')}-01`;

  let formattedDate2 = `${formattedDate}`;
  return formattedDate2
}
const to_day1 = () => {
  // 获取当前日期
  let currentDate = new Date();

  // 计算上个月的年份和月份
  let year = currentDate.getMonth() === 0 ? currentDate.getFullYear() - 1 : currentDate.getFullYear();
  let month = currentDate.getMonth() === 0 ? 11 : currentDate.getMonth() - 1;

  // 获取上个月的最后一天
  let lastDayOfLastMonth = new Date(year, month + 1, 0);

  // 格式化为 yyyy-mm-dd
  let formattedDate = `${lastDayOfLastMonth.getFullYear()}-${(lastDayOfLastMonth.getMonth() + 1).toString().padStart(2, '0')}-${lastDayOfLastMonth.getDate()}`;

  let formattedDate2 = `${formattedDate}`;
  return formattedDate2
}
const find_data = reactive({

  driverUserId: "",
  etime: "",
  plateNums: [],
  stime: "",
  carBelongType: "0",

})
const list_data = ref({})
const carBelongType_off = ref('0')
const list_api = () => {
  carBelongType_off.value = find_data.carBelongType
  revenueSum(find_data).then(res => {
    list_data.value = res.data
  })
}
const plateNumsname = computed(() => {
  let data = '全部车辆'
  if (find_data.plateNums.length > 0) {
    if (find_data.plateNums.length > 3) {
      data = find_data.plateNums[0] + ',' + find_data.plateNums[1] + ',' + find_data.plateNums[2] + ',' + '等' + find_data.plateNums.length + '辆车'
    } else {
      data = find_data.plateNums.join(',')
    }
  } else {
    data = '全部车辆'
  }
  return data
})

const ex_getWalletListForBack_btn = () => {
  if (carBelongType_off.value == '0') {
    let title = luser.value.companyName + '自营车辆营收统计表.xlsx'
    let ps = {
      driverUserId: find_data.driverUserId,
      etime: find_data.etime,
      plateNums: find_data.plateNums,
      stime: find_data.stime,
      carBelongType: find_data.carBelongType,
    }

    revenueSum(ps).then(res => {
      if (res.code == 1) {
        let data = []
        // 表名
        let table_1 = [luser.value.companyName + '车辆营收统计表', "", "", "", "", "",]
        data.push(table_1)
        // 第一排
        let table_2 = ['车牌号', plateNumsname.value, "", "", "", "",]
        data.push(table_2)
        // 第二排
        let table_3 = ['时间周期', timeTypeTime.value[0], "", "至", timeTypeTime.value[1], "",]
        data.push(table_3)
        // 第三排
        let table_4 = ['自营收入', '项目', "总金额", "已收款", '未收款', "未收款比",]
        data.push(table_4)
        // 第四排
        let table_5 = ['', '总收入', list_data.value.totalPrice, list_data.value.totalAlGathPrice, list_data.value.totalGathSubPrice, Math.round(list_data.value.totalNoGathRatio * 100) + '%',]
        data.push(table_5)
        // 第五排
        let table_6 = ['', '行程收入', list_data.value.totalBcPrice, list_data.value.totalBcAlGathPrice, list_data.value.totalBcGathSubPrice, Math.round(list_data.value.totalBcNoGathRatio * 100) + '%',]
        data.push(table_6)
        // 第六排
        let table_7 = ['', '接送收入', list_data.value.totalJsPrice, list_data.value.totalJsAlGathPrice, list_data.value.totalJsGathSubPrice, Math.round(list_data.value.totalJsNoGathRatio * 100) + '%',]
        data.push(table_7)
        // 第七排
        let table_8 = ['', '其他收入', list_data.value.totalOtherGath, list_data.value.totalOtherAlGath, list_data.value.totalOtherNoGath, Math.round(list_data.value.totalOtherAlGathRatio * 100) + '%',]
        data.push(table_8)
        // 第八排
        let table_9 = ['行程开支', '项目', "总金额", "已支付", '未支付	', "开支比",]
        data.push(table_9)
        // 第九排
        let table_10 = ['', '总开支', list_data.value.totalPay, list_data.value.totalAlPay, list_data.value.totalNoPay, Math.round(list_data.value.totalPayRatio * 100) + '%',]
        data.push(table_10)
        // 第十排
        let table_11 = ['', '停车费', list_data.value.parkingFee, list_data.value.parkingFeeAlPay, list_data.value.parkingFeeNoPay, Math.round(list_data.value.parkingFeeRatio * 100) + '%',]
        data.push(table_11)
        // 第十一排
        let table_12 = ['', '过路费', list_data.value.roadFee, list_data.value.roadFeeAlPay, list_data.value.roadFeeNoPay, Math.round(list_data.value.roadFeeRatio * 100) + '%',]
        data.push(table_12)
        // 第十二排
        let table_13 = ['', '餐费', list_data.value.livingFee, list_data.value.livingFeeAlPay, list_data.value.livingFeeNoPay, Math.round(list_data.value.livingFeeRatio * 100) + '%',]
        data.push(table_13)
        // 第十三排
        let table_14 = ['', '住宿费', list_data.value.stayFee, list_data.value.stayFeeAlPay, list_data.value.stayFeeNoPay, Math.round(list_data.value.stayFeeRatio * 100) + '%',]
        data.push(table_14)
        // 第十四排
        let table_15 = ['', '买水费', list_data.value.waterFee, list_data.value.waterFeeAlPay, list_data.value.waterFeeNoPay, Math.round(list_data.value.waterFeeRatio * 100) + '%',]
        data.push(table_15)
        // 第十五排
        let table_16 = ['', '洗车费', list_data.value.washingFee, list_data.value.washingFeeAlPay, list_data.value.washingFeeNoPay, Math.round(list_data.value.washingFeeRatio * 100) + '%',]
        data.push(table_16)
        // 第十六排
        let table_17 = ['', '打的费', list_data.value.taxiFee, list_data.value.taxiFeeAlPay, list_data.value.taxiFeeNoPay, Math.round(list_data.value.taxiFeeRatio * 100) + '%',]
        data.push(table_17)
        // 第十七排
        let table_18 = ['', '打单费', list_data.value.singleFee, list_data.value.singleFeeAlPay, list_data.value.singleFeeNoPay, Math.round(list_data.value.singleFeeRatio * 100) + '%',]
        data.push(table_18)
        // 第十八排
        let table_19 = ['', '其他费', list_data.value.otherFee, list_data.value.otherFeeAlPay, list_data.value.otherFeeNoPay, Math.round(list_data.value.otherFeeRatio * 100) + '%',]
        data.push(table_19)
        // 第十九排
        let table_20 = ['其他开支', '项目', "总金额", "已支付", '未支付	', "开支比",]
        data.push(table_20)
        // 第二十排
        let table_21 = ['', '总开支', list_data.value.totalOfficePay, list_data.value.totalOfficeAlPay, list_data.value.totalOfficeNoPay, Math.round(list_data.value.totalOfficePayRatio * 100) + '%',]
        data.push(table_21)
        // 第二一排
        let table_22 = ['', '司机工资', list_data.value.salaryFee, list_data.value.salaryFeeAlPay, list_data.value.salaryFeeNoPay, Math.round(list_data.value.salaryFeeRatio * 100) + '%',]
        data.push(table_22)
        // 第二二排
        let table_23 = ['', '油费', list_data.value.oilFee, list_data.value.oilFeeAlPay, list_data.value.oilFeeNoPay, Math.round(list_data.value.oilFeeRatio * 100) + '%',]
        data.push(table_23)
        // 第二三排
        let table_24 = ['', '维修费', list_data.value.repairFee, list_data.value.repairFeeAlPay, list_data.value.repairFeeNoPay, Math.round(list_data.value.repairFeeRatio * 100) + '%',]
        data.push(table_24)
        // 第二四排
        let table_25 = ['', '保养费', list_data.value.maintenanceFee, list_data.value.maintenanceFeeAlPay, list_data.value.maintenanceFeeNoPay, Math.round(list_data.value.maintenanceFeeRatio * 100) + '%',]
        data.push(table_25)
        // 第二五排
        let table_26 = ['', '业务赔款', list_data.value.compensateFee, list_data.value.compensateFeeAlPay, list_data.value.compensateFeeNoPay, Math.round(list_data.value.compensateFeeRatio * 100) + '%',]
        data.push(table_26)
        // 第二六排
        let table_27 = ['', '规费', list_data.value.guiFee, list_data.value.guiFeeAlPay, list_data.value.guiFeeNoPay, Math.round(list_data.value.guiFeeRatio * 100) + '%',]
        data.push(table_27)
        // 第二七排
        let table_28 = ['', '车辆保险', list_data.value.insuranceFee, list_data.value.insuranceFeeAlPay, list_data.value.insuranceFeeNoPay, Math.round(list_data.value.insuranceFeeRatio * 100) + '%',]
        data.push(table_28)
        // 第二八排
        let table_29 = ['', '其他开支', list_data.value.otherMoreFee, list_data.value.otherMoreFeeAlPay, list_data.value.otherMoreFeeNoPay, Math.round(list_data.value.otherMoreFeeRatio * 100) + '%',]
        data.push(table_29)
        // 第二九排
        let table_30 = ['利润', '项目', "总金额", "", '	', "利润比",]
        data.push(table_30)
        // 第三十排
        let table_31 = ['', '毛利润', list_data.value.grossProfit, '', "", Math.round(list_data.value.grossProfitRatio * 100) + '%',]
        data.push(table_31)
        const ws = XLSX.utils.aoa_to_sheet(data);

        ws['!merges'] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 5 } }] // 合并第一行的6个单元格
        ws['!merges'].push({ s: { r: 1, c: 1 }, e: { r: 1, c: 5 } }) // 合并第二行的5个单元格
        // 设置第三行的单元格合并情况
        ws['!merges'].push({ s: { r: 2, c: 1 }, e: { r: 2, c: 2 } }) // 合并第三行的第二和第三个单元格
        ws['!merges'].push({ s: { r: 2, c: 4 }, e: { r: 2, c: 5 } })// 合并第三行的第五和第六个单元格
        // 合并第四行到第八行的第一个单元格
        ws['!merges'].push({ s: { r: 3, c: 0 }, e: { r: 7, c: 0 } });
        // 合并第九行到第十九行的第一个单元格
        ws['!merges'].push({ s: { r: 8, c: 0 }, e: { r: 18, c: 0 } });
        // 合并第二十行到第二九行的第一个单元格
        ws['!merges'].push({ s: { r: 19, c: 0 }, e: { r: 28, c: 0 } });
        // 合并第三十行到第三一行的第一个单元格
        ws['!merges'].push({ s: { r: 29, c: 0 }, e: { r: 30, c: 0 } });



        ws['!cols'] = [{ width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }, { width: 10 },];

        // // 设置所有单元格内容垂直水平居中
        // Object.keys(ws).filter((cell) => cell !== '!ref' && cell !== '!merges').forEach((cell) => {
        //   ws[cell].s = {
        //     alignment: { horizontal: 'center', vertical: 'center' },
        //   };
        // });


        const wb = XLSX.utils.book_new();


        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
        XLSX.writeFile(wb, title);

        return ElMessage({
          message: res.msg,
          type: 'success',
        })
      } else {
        return ElMessage({
          message: res.msg,
          type: 'warning',
        })
      }

    })
  } else if (carBelongType_off.value == '1') {
    let title = luser.value.companyName + '车辆营收统计表.xlsx'
    let ps = {
      driverUserId: find_data.driverUserId,
      etime: find_data.etime,
      plateNums: find_data.plateNums,
      stime: find_data.stime,
      carBelongType: find_data.carBelongType,
    }

    revenueSum(ps).then(res => {
      if (res.code == 1) {



        let data = []
        // 表名
        let table_1 = [luser.value.companyName + '外调车辆营收统计表', "", "", "", "", "",]
        data.push(table_1)
        // 第一排
        let table_2 = ['车牌号', plateNumsname.value, "", "", "", "",]
        data.push(table_2)
        // 第二排
        let table_3 = ['时间周期', timeTypeTime.value[0], "", "至", timeTypeTime.value[1], "",]
        data.push(table_3)
        // 第三排
        let table_4 = ['外调收入', '项目', "总金额", "已收款", '未收款', "未收款比",]
        data.push(table_4)
        // 第四排
        let table_5 = ['', '总收入', list_data.value.totalPrice, list_data.value.totalAlGathPrice, list_data.value.totalGathSubPrice, Math.round(list_data.value.totalNoGathRatio * 100) + '%',]
        data.push(table_5)
        // 第五排
        let table_6 = ['', '行程收入', list_data.value.totalBcPrice, list_data.value.totalBcAlGathPrice, list_data.value.totalBcGathSubPrice, Math.round(list_data.value.totalBcNoGathRatio * 100) + '%',]
        data.push(table_6)
        // 第六排
        let table_7 = ['', '接送收入', list_data.value.totalJsPrice, list_data.value.totalJsAlGathPrice, list_data.value.totalJsGathSubPrice, Math.round(list_data.value.totalJsNoGathRatio * 100) + '%',]
        data.push(table_7)

        // 第七排
        let table_8 = ['外调开支', '项目', "总金额", "已支付", '未支付	', "开支比",]
        data.push(table_8)
        // 第八排
        let table_9 = ['', '总开支', list_data.value.totalOutPrice, list_data.value.totalOutAIPrice, list_data.value.totalOutSubPrice, Math.round(list_data.value.totalOutNoPayRatio * 100) + '%',]
        data.push(table_9)
        // 第九排
        let table_10 = ['利润', '项目', "总金额", "", '	', "利润比",]
        data.push(table_10)
        // 第十排
        let table_11 = ['', '毛利润', list_data.value.grossProfit, '', "", Math.round(list_data.value.grossProfitRatio * 100) + '%',]
        data.push(table_11)
        const ws = XLSX.utils.aoa_to_sheet(data);

        ws['!merges'] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 5 } }] // 合并第一行的6个单元格
        ws['!merges'].push({ s: { r: 1, c: 1 }, e: { r: 1, c: 5 } }) // 合并第二行的5个单元格
        // 设置第三行的单元格合并情况
        ws['!merges'].push({ s: { r: 2, c: 1 }, e: { r: 2, c: 2 } }) // 合并第三行的第二和第三个单元格
        ws['!merges'].push({ s: { r: 2, c: 4 }, e: { r: 2, c: 5 } })// 合并第三行的第五和第六个单元格
        // 合并第四行到第七行的第一个单元格
        ws['!merges'].push({ s: { r: 3, c: 0 }, e: { r: 6, c: 0 } });
        // 合并第八行到第九行的第一个单元格
        ws['!merges'].push({ s: { r: 7, c: 0 }, e: { r: 8, c: 0 } });
        // 合并第十行到第十一行的第一个单元格
        ws['!merges'].push({ s: { r: 9, c: 0 }, e: { r: 10, c: 0 } });



        ws['!cols'] = [{ width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }, { width: 10 }, { width: 10 },];




        const wb = XLSX.utils.book_new();


        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
        XLSX.writeFile(wb, title);

        return ElMessage({
          message: res.msg,
          type: 'success',
        })
      } else {
        return ElMessage({
          message: res.msg,
          type: 'warning',
        })
      }

    })
  }

}
</script>

<style scoped lang='less'>
table {
  border-collapse: collapse;
  /* 合并单元格边框 */
  width: 100%;
  /* 表格宽度 */
}

td,
th,
tr {
  border: 1px solid #5e8fe5;
  /* 单元格边框样式 */
  padding: 2px;
  /* 单元格内边距 */
  text-align: center;
  width: 500px;
  vertical-align: middle;
  /* 文本居中 */
}

th {
  font-weight: 700;
}

td {
  font-size: 12px;

}

.td1 {
  font-weight: 700;
}

.td2 {
  background-color: #fedb61;
}

.td3 {
  background-color: #add88d;
}

.td4 {
  background-color: #ef949f;
}

.time-wrapper {
  display: flex;
  justify-content: space-between;
  padding-bottom: 5px;

  .bigTitle {
    display: inline-block;
    border-bottom: none;
    padding: 8px 0;
    color: #3A71A8;
    margin-right: 20px;
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
  }
}

.time-wrapper2 {
  display: flex;
  padding-bottom: 5px;

  .bigTitle {
    display: inline-block;
    border-bottom: none;
    padding: 8px 0;
    color: #3A71A8;
    margin-right: 20px;
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
  }
}

::v-deep(.empty-car-list) {
  overflow: hidden;
  @borderColor: #1890ff;

  .car-list {
    display: inline-block;
    vertical-align: top;
    margin-left: 10px;

    .c-gray {
      display: block;
      text-align: center;
      font-size: 15px;
      padding: 20px 0 40px 0;
      color: #929292 !important;
    }

    .sort_wrapper {
      display: inline-block;
      vertical-align: top;
      width: 50px;
      text-align: center;
      border: 1px solid @borderColor;

      .sort_title {
        width: 50px;
        font-size: 12px;
        height: 20px;
        line-height: 20px;
        color: white;
        background: #393B6A;
      }

      .sort_empty {
        width: 50px;
        height: 21px;
        line-height: 20px;
        background: #ecebeb;
        border-bottom: 1px solid @borderColor;
      }

      .sort_item {
        width: 50px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        border-bottom: 1px solid @borderColor;

        &:last-child {
          border-bottom: none;
        }
      }
    }
  }

  .toggleOpen {
    width: 20px;
    display: inline-block;
    vertical-align: top;
    text-align: center;
    line-height: 343px;
    height: 343px;
    background: #f5f5f5;
    margin-left: -1px;
    border: 1px solid @borderColor;

    &:hover {
      cursor: pointer;
      background: #e8e8e8;

      i {
        color: @borderColor;
      }
    }
  }

  .throw_wrapper {
    display: inline-block;
    vertical-align: top;
    margin-left: -1px;
    border: 1px solid @borderColor;
    border-top: none;
    box-sizing: border-box;

    .title {
      background: #393B6A;
      color: #fff;
      height: 21px;
      line-height: 20px;
      font-size: 12px;
      text-align: center;
    }

    .content_wrapper {
      display: flex;
      padding-top: 1px;

      .items {
        width: 70px;
        text-align: center;
        font-size: 12px;
        font-weight: normal;
        border-right: 1px solid #1890ff;
        overflow: hidden;

        &:last-child {
          border-right: none;
        }

        .smallTitle {
          height: 20px;
          line-height: 20px;
          background: #ecebeb;
          border-bottom: 1px solid #1890ff;
        }

        .error_item {
          height: 20px;
          line-height: 20px;
          box-sizing: border-box;
          border-bottom: 1px solid #1890ff;

          &:last-child {
            border-bottom: none;
          }
        }
      }
    }
  }

  .toggleMore {
    width: 100%;
    text-align: center;
    padding: 10px 0;
    font-size: 14px;
    border: 1px solid @borderColor;
    border-top: none;

    &:hover {
      cursor: pointer;
      color: @borderColor;
    }
  }

}
</style>
